package cc.service;

import cc.entity.Test;
import cc.repository.TestRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * TODO
 *
 * @author My
 * @date 2021/6/22 14:57
 */
@Service
public class TestServiceImpl implements ITestService {

    @Autowired
    TestRepository testRepository;
    @Override
    public List<Test> list() {
        return testRepository.listAll();
    }
    //查
    @Override
    public Test findbyid(Integer id) {
        return testRepository.findById(id).get();
    }
    //查（name）
    @Override
    public Test findbyname(String d_name) {
        return testRepository.findbyname(d_name);
    }
    //删
    @Override
    public Test deletebyid(Integer id) {
        testRepository.deletebyid(id);
        return null;
    }
    //改
    @Override
    public Test updatename(String d_name, Integer id)
    {
        testRepository.updatename(d_name,id);
        return null;
    }
    //增
    @Override
    public Test addbyid(Integer id,String d_name) {
        Test n = new Test();
        n.setId(id);
        n.setNum(d_name);
        testRepository.save(n);
        return n;
    }
}
